﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ModelLayer;

namespace DBLayer
{
    public class MovieDBDummy
    {
        private Movie testMovie;
        private Movie testMovie2 = null;
        private int currentId = 0;
        

        public MovieDBDummy()
        {
            testMovie = CreateTestMovie();
        }

        public Movie CreateTestMovie()
        {
            string[] actors = { "actor1", "actor2", "actor3" };
            DateTime d1 = new DateTime(2012, 10, 15);
            DateTime d2 = new DateTime(2012, 11, 20);
            Movie m1 = new Movie(true, "Title", 200, "actor", 15, "Blarghh", "PG:13", "Steven Spegepølse", "Komedie", "Swahili", 9001, "Gerbal Rentals", d1, d2);

            return m1;
        }



        public int GetNextMovieId()
        {
            throw new NotImplementedException();
        }

        public int InsertMovie(Movie m)
        {
            testMovie = m;
            currentId++;
            testMovie.Id = currentId;
            return currentId;
            
        }

        public Movie GetMovie(string title)
        {
            Movie returnMovie;
            if (testMovie2 != null)
            {
                returnMovie = testMovie2;
                testMovie2 = null;
            }
            else if (testMovie == null)
            {
                returnMovie = null;
                testMovie = CreateTestMovie();
            }
            else
            {
                returnMovie = testMovie;
            }

            return returnMovie;
        }

        public List<Movie> GetMovies(DateTime dateTime)
        {
            List<Movie> returnList = new List<Movie>();

            if ((testMovie.RentalDateStart.CompareTo(dateTime) < 0) && ( testMovie.RentalDateEnd.CompareTo(dateTime) > 0))
            returnList.Add(testMovie);

            return returnList;
        }

        public void UpdateMovie(Movie m)
        {
            testMovie2 = m;
        }

        public int DeleteMovie(int id)
        {
            testMovie = null;
            return 1;
        }

        public List<Movie> FindMovies(string input, string category)
        {
            List<Movie> movies = new List<Movie>();
            Movie returnMovie = CreateTestMovie();
            movies.Add(returnMovie);
            string[] actors = { "actor1", "actor2", "actor4" };
            DateTime d1 = new DateTime(2012, 10, 16);
            DateTime d2 = new DateTime(2012, 11, 21);
            Movie m2 = new Movie(true, "Title1", 200, "actor", 15, "Blargh", "PG:13", "Steven Spegepølse", "Komedie", "Swahili", 9001, "Gerbal Rentals", d1, d2);
            movies.Add(m2);
            return movies;
        }
    }
}
